package com.ruoyi.web.controller.shop;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.shop.domain.GoodsElement;
import com.ruoyi.shop.service.IGoodsElementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品元素Controller
 * 
 * @author ruoyi
 * @date 2025-10-16
 */
@Api("商品元素")
@RestController
@RequestMapping("/shop/goodsElement")
public class GoodsElementController extends BaseController
{
    @Autowired
    private IGoodsElementService goodsElementService;

    /**
     * 查询商品元素列表
     */
    @ApiOperation("查询商品元素列表")
    @GetMapping("/list")
    public TableDataInfo list(GoodsElement goodsElement)
    {
        startPage();
        List<GoodsElement> list = goodsElementService.selectGoodsElementList(goodsElement);
        return getDataTable(list);
    }

    /**
     * 导出商品元素列表
     */

    @Log(title = "商品元素", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsElement goodsElement)
    {
        List<GoodsElement> list = goodsElementService.selectGoodsElementList(goodsElement);
        ExcelUtil<GoodsElement> util = new ExcelUtil<GoodsElement>(GoodsElement.class);
        util.exportExcel(response, list, "商品元素数据");
    }

    /**
     * 获取商品元素详细信息
     */
    @ApiOperation("获取商品元素详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(goodsElementService.selectGoodsElementById(id));
    }

    /**
     * 新增商品元素
     */
    @ApiOperation("新增商品元素")
    @Log(title = "商品元素", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsElement goodsElement)
    {
        return toAjax(goodsElementService.insertGoodsElement(goodsElement));
    }

    /**
     * 修改商品元素
     */
    @ApiOperation("修改商品元素")
    @Log(title = "商品元素", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsElement goodsElement)
    {
        return toAjax(goodsElementService.updateGoodsElement(goodsElement));
    }

    /**
     * 删除商品元素
     */
    @ApiOperation("删除商品元素")
    @Log(title = "商品元素", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodsElementService.deleteGoodsElementByIds(ids));
    }
}
